package com.generator.sysManage.areaManage.service.impl;

import com.generator.sysManage.areaManage.dao.AreaInfoMapper;
import com.generator.sysManage.areaManage.pojo.AreaManageInfom;
import com.generator.sysManage.areaManage.service.AreaManageService;
import com.generator.util.PageModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shkstart
 * @create 2022-10-03 17:40
 */
@Service
public class AreaManageServiceImp implements AreaManageService {
    @Autowired
    private AreaInfoMapper areaInfoMapper;
    @Override
    public PageModel<AreaManageInfom> getAreaInfom(AreaManageInfom area, PageModel<AreaManageInfom> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?3:pageModel.getPageSize());
        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<AreaManageInfom> areaList = areaInfoMapper.getAreaInfo(area);
        PageInfo<AreaManageInfom> pageInfo = new PageInfo<AreaManageInfom>(areaList);
        pageModel.setData(new ArrayList<AreaManageInfom>(areaList));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }
}
